import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import AddEditModal from '#cpt/temp/AddEditModal'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 提交表单列表
		formData : [
			{ label: '设备名称',		name: 'device_id',		type: 'select', loading:true, required:true, half:true, data: [],onValue:({ rows, ref })=>{
				if(rows){
					const { device_number, device_model  } = rows
					ref.setValue({ device_number, device_model })
					
					$http.submit(null,'project-team/info',{param:{uuid:rows.pgroup_id}}).then( ({ project_name }) => {
						ref.setValue({ project_name })
					})
				}else{
					ref.reset(['device_number','device_model'])
				}
			} },
			{ label: '设备编号',				name: 'device_number', 		half:true,	disabled:true },
			{ label: '设备型号',				name: 'device_model', 		half:true,	disabled:true },
			{ label: '总故障时间',			name: 'total_time', 		half:true },
			{ label: '维修后确认方式',		name: 'con_mode', 			half:true },
			{ label: '故障日期',				name: 'fault_time', 		half:true },
			{ label: '所属科室',				name: 'project_name', 		half:true,	disabled:true },
			{ label: '厂商维修人员',			name: 'repair_user', 		half:true },
			{ label: '维护日期',				name: 'repair_time', 		half:true },
			{ label: '故障原因',     		name: 'fault_reason', 		full:true,	 type:'textarea' },
			{ label: '修理情况概述',     	name: 'reason', 			full:true,	 type:'textarea' },
			{ label: '对病人结果的影响',     	name: 'result_infl', 		full:true,	 type:'textarea' },
			{ label: '操作人员',     		name: 'operator_user', 		half:true, },
			{ label: '日期',     			name: 'operator_time', 		half:true, },
			{ label: '审核人员',     		name: 'auditor', 			half:true, },
			{ label: '日期',     			name: 'auditor_time', 		half:true },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.fetch()
	}
	
	// 获取弹窗下拉框数据
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, 'device_id', ()=>{
			$cache.then( async f => {
				// 设备名称
				$fn.setRow(formData, 'device_id', await f.getDivCache())
				//
				this.setState({ formData })
			})
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'de-repair-log/index')
	
	// 表单
	cols = [
		{ title: '设备名称',				dataIndex: 'device_name', 		width:100 },
		{ title: '设备型号', 			dataIndex: 'device_model', 		width:150 },
		{ title: '故障日期', 			dataIndex: 'fault_time', 		width:150 },
		{ title: '故障原因', 			dataIndex: 'fault_reason', 		width:80, 	align:'center' },
		{ title: '厂家维修人员', 		dataIndex: 'repair_user', 		width:150 },
		{ title: '状态', 				dataIndex: 'imple_user', 		width:150 },
		TableControls.controls.call(this)
	]

	// 表格操作按钮
	table_controls = (text,{ uuid }) => [
		TableControls.edit.call(this, 'de-repair-log/info', { uuid }, { label:'故障设备明细', select:this.getModalSelect })
	]
	
	// 操作按钮
	controls = () =>[
		Controls.add.call(this,{label:'维修新增记录', click:this.getModalSelect}),
		Controls.back.call(this)
	]
	
	render(){
		return (
			<>
				<Page title='维修记录' controls={this.controls()}>
					<div className='h10'></div>
					{/* 表格 */}
					{ Table.call(this) }
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ width:'50%', minWidth:800, height:'95%', labelWidth:'s8', addText:'维修新增记录', editText:'故障设备明细', scroll:true,  api: 'de-repair-log/add', editApi:'de-repair-log/edit' }) }
			</>
		)
	}
}

export default Index